package com.sinodata.atmp.components
{
    import mx.validators.Validator;
    import mx.validators.StringValidator;
    import mx.core.UITextField;
    import mx.controls.TextInput;

    public class DifferenceValidator extends StringValidator {
        import mx.validators.Validator;
        import mx.validators.ValidationResult;
    
        private var results:Array;        
        public function DifferenceValidator(){
            super();
        }
        
        public var secondSource:TextInput;
        public var noSecondSourceError:String = "Not specified secondsource";
        public var differenceError:String = "Difference value";
                
        override protected function doValidation(value:Object):Array{
            results = [];       
            results = super.doValidation(value);
            if (results.length > 0)
            return results;
            
            if(secondSource != null){
                var password1:String = secondSource.text;
                if(password1.length > 0){
                    if(password1 != value.toString()){
                        results.push(new ValidationResult(true, null, "Diff",differenceError));
                        return results;
                    }
                }
            }else{
                results.push(new ValidationResult(true, null, "NaN",noSecondSourceError));
                return results;
            }
            return results;
        }
    }
}